/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "dal_fastdds/converter/InstanceHandleConverter.hpp"

TEST(test_convert_instance_handle_from_fastdds_to_dal, instance_handle_convert_default)
{
    dal_instance_handle_t d_ins;
    InstanceHandle_t f_ins;
    d_ins.segment_0_ = 0x00112233;
    d_ins.segment_1_ = 0x44556677;
    d_ins.segment_2_ = 0x8899AABB;
    d_ins.segment_3_ = 0xCCDDEEFF;
    dal_ret_t ret = InstanceHandleConverter::GetInstance()->ConvertInstanceHandleFromDalToFastdds(
        &d_ins, &f_ins);
    EXPECT_EQ(ret, DAL_RETCODE_OK);
    EXPECT_EQ(f_ins.value[0], 0x33);
    EXPECT_EQ(f_ins.value[1], 0x22);
    EXPECT_EQ(f_ins.value[2], 0x11);
    EXPECT_EQ(f_ins.value[3], 0x00);
    EXPECT_EQ(f_ins.value[4], 0x77);
    EXPECT_EQ(f_ins.value[5], 0x66);
    EXPECT_EQ(f_ins.value[6], 0x55);
    EXPECT_EQ(f_ins.value[7], 0x44);
    EXPECT_EQ(f_ins.value[8], 0xBB);
    EXPECT_EQ(f_ins.value[9], 0xAA);
    EXPECT_EQ(f_ins.value[10], 0x99);
    EXPECT_EQ(f_ins.value[11], 0x88);
    EXPECT_EQ(f_ins.value[12], 0xFF);
    EXPECT_EQ(f_ins.value[13], 0xEE);
    EXPECT_EQ(f_ins.value[14], 0xDD);
    EXPECT_EQ(f_ins.value[15], 0xCC);
}

TEST(test_convert_instance_handle_from_dal_to_fastdds, instance_handle_convert_default)
{
    dal_instance_handle_t d_ins;
    InstanceHandle_t f_ins;
    f_ins.value[0] = 0x33;
    f_ins.value[1] = 0x22;
    f_ins.value[2] = 0x11;
    f_ins.value[3] = 0x00;
    f_ins.value[4] = 0x77;
    f_ins.value[5] = 0x66;
    f_ins.value[6] = 0x55;
    f_ins.value[7] = 0x44;
    f_ins.value[8] = 0xBB;
    f_ins.value[9] = 0xAA;
    f_ins.value[10] = 0x99;
    f_ins.value[11] = 0x88;
    f_ins.value[12] = 0xFF;
    f_ins.value[13] = 0xEE;
    f_ins.value[14] = 0xDD;
    f_ins.value[15] = 0xCC;
    dal_ret_t ret = InstanceHandleConverter::GetInstance()->ConvertInstanceHandleFromFastddsToDal(
        &f_ins, &d_ins);
    EXPECT_EQ(ret, DAL_RETCODE_OK);
    EXPECT_EQ(d_ins.segment_0_, 0x00112233);
    EXPECT_EQ(d_ins.segment_1_, 0x44556677);
    EXPECT_EQ(d_ins.segment_2_, 0x8899AABB);
    EXPECT_EQ(d_ins.segment_3_, 0xCCDDEEFF);
}